package com.order.controller.user;


import com.order.entity.OrderDetail;
import com.order.entity.OrderHistory;
import com.order.result.Result;
import com.order.service.OrderService;
import com.order.vo.OrderDetailVo;
import com.order.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "用户-订单管理接口")
public class OrderController {

    @Autowired
    private OrderService orderService;
    @ApiOperation("历史订单查询")
    @GetMapping
    public Result<OrderVo> getOrderHistory(){
        List<OrderHistory> orderHistory = orderService.getOrderHistory();
        OrderVo orderVo = OrderVo.builder()
                .num(orderHistory.size())
                .orders(orderHistory)
                .build();
        return Result.success(orderVo);
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/{orderId}")
    public Result<OrderDetailVo> getOrderDetail(@PathVariable Long orderId){
        List<OrderDetail> orderDetail = orderService.getOrderDetail(orderId);
        OrderDetailVo orderDetailVo = OrderDetailVo.builder()
                .num(orderDetail.size())
                .orderDetails(orderDetail)
                .build();
        return Result.success(orderDetailVo);
    }

}
